export default {
    namespaced: true,
    state: {
      productData: [],
    },
    mutations: {
      SET_PRODUCTS(state, payload) {
        state.productData = payload;
      },
      DECREASE_INVENTORY(state, payload) {
        let target = state.productData.find((item) => item.id === payload.id);
        target.inventory--;
      },
      INCREASE_INVENTORY(state, payload) {
        let target = state.productData.find((item) => item.id === payload.id);
        target.inventory++;
      },
    },
    actions: {
      async FETCH_PRODUCTS(context) {
        const res = await fetch("http://chst.vip/data/index.json").then((body) =>
          body.json()
        );
        context.commit("SET_PRODUCTS", res.data);
      },
    },
    getters: {},
  };
  